import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

public class Leet1578 {
    public static void main(String[] args) {
        Leet1578 l = new Leet1578();
        System.out.println(l.minCost("abaac", new int[]{1,2,3,4,5}));
    }

    public int minCost(String s, int[] cost) {
        char[] t = s.toCharArray();
        int sum = 0;
        for(int i = 1;i<t.length;i++)
            if (t[i]==t[i-1])
                if(cost[i]>=cost[i-1]) sum+=cost[i-1];
                else {
                    sum+=cost[i];
                    cost[i] = cost[i-1];
                }
        return sum;
    }
}
